import axios from 'axios';
// axios.defaults.withCredentials = false;
const baseURL = ''
const request = axios.create({
    baseURL: baseURL,
    timeout: 5000,
    withCredentials:true,
})

request.interceptors.request.use(
    config => {
        return config
    },
    error => Promise.reject(error)
)
request.interceptors.response.use(
    response => {
        if (response.data.status !== 200) { 
            return Promise.reject(response.data)
        }
        return response.data;
    },
    error => {
        closeToast();
        if (error && error.response) {
            // 根据约定的响应码处理
            switch (error.response.status) {
                case 403:
                    error.message = '拒绝访问';
                    break;
                case 502:
                    error.message = '服务器端出错';
                    break;
                default:
                    error.message = `连接错误${error.response.status}`;
            }
        } else {
            // 超时处理
            error.message = '服务器响应超时，请刷新当前页';
        }
        // showToast(error.message);
        return Promise.resolve(error.response);
    }
)
export { request }